package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.Contant;
import com.example.xianji.R;
import com.example.xianji.bean.Replay;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Replay_Adapter extends BaseAdapter {
    private ArrayList<Replay> replay_list;
    private Context mContext;


    public Replay_Adapter(ArrayList<Replay> replay_list, Context mContext) {
        super();
        this.replay_list = replay_list;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return replay_list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        Holder mHolder;
        if (arg1 == null) {
            mHolder = new Holder();
            arg1 = View.inflate(mContext, R.layout.replay_listview_item, null);
            mHolder.replay_name = (TextView) arg1.findViewById(R.id.replay_name);
            mHolder.replay_details = (TextView) arg1.findViewById(R.id.replay_details);
            mHolder.replay_time = (TextView) arg1.findViewById(R.id.replay_time);
            mHolder.image_replay_touxiang = (ImageView) arg1.findViewById(R.id.image_replay_touxiang);
            arg1.setTag(mHolder);
        }
        mHolder = (Holder) arg1.getTag();
        mHolder.replay_name.setText(replay_list.get(arg0).getNickname());
        mHolder.replay_details.setText(replay_list.get(arg0).getDetail());
        mHolder.replay_time.setText(replay_list.get(arg0).getUpdated_at());
        ImageLoader.getInstance().displayImage(Contant.replay_touxiang + replay_list.get(arg0).getAvatar(), mHolder.image_replay_touxiang);
        return arg1;
    }

    class Holder {
        TextView replay_name;
        TextView replay_details;
        TextView replay_time;
        ImageView image_replay_touxiang;
    }

}
